import types from './types';
import http from '@/utils/http';
import auth from '@/utils/auth';

export default {
  resetState ({ commit }, payload) {
    commit(types.RESET_STATE, payload);
  },

  async doLogin ({ commit }, payload) {
    const res = await http({
      method: 'POST',
      url: '/api/admin/user/login',
      data: payload,
      showMessage: false
    });
    return res;
  },

  async getUserInfo ({ commit }, payload) {
    http({
      method: 'GET',
      url: '/api/admin/user/current',
      data: payload,
      showMessage: false
    }).then(res => {
      commit('SET_USER_INFO', res.data);
      auth.setUserInfo(res.data);
    });
  }
};
